package com.neuedu.service.impl;

import com.neuedu.dao.AdminDao;
import com.neuedu.entity.Admin;
import com.neuedu.service.AdminService;

import java.util.List;

public class AdminServiceImpl implements AdminService {
    AdminDao adminDao=new AdminDao();
    @Override
    public boolean register(Admin admin) {
        System.out.print("success");
        List<Admin> list=adminDao.findByWhere(" and adminName='"+ admin.getAdminName()+"'");

            if(list.size()==0){
                return  adminDao.insert(admin);
        }
        return false;
    }

    @Override
    public Admin login(String adminName, String password) {
        String where=" and adminName='"+ adminName+"' AND password='"+password+"'";
        List<Admin> list=adminDao.findByWhere(where);
        if(list.size()>0){
            return  list.get(0);
        }
        return null;
    }
    public static void main(String[] args){
        AdminServiceImpl adminService=new AdminServiceImpl();
//        Admin admin=new Admin();
//        admin.setAdminName("李四");
//        admin.setPassword("000000");
//        admin.setCreatetime(new Date());
//        if(adminService.register(admin)){
//            System.out.print("注册成功");
//        }
//        else {
//            System.out.print("注册失败");
//        }
        Admin admin=adminService.login("李四","000000");
        if (null!=admin){
            System.out.print("登陆成功");
        }
        else {
            System.out.print("登陆失败");
        }

    }
}
